package com.oodso.say.utils;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目名称：Sosoliuda
 * 类描述：退出类（装载activity）
 * 创建人：周作威
 * 创建时间：2016/11/11
 */

public class SignoutUtils {
    private static List<Activity> list;
    private String appkey;
    private String sercet;

    private static class SignoutHolder {
        /**
         * 单例对象实例
         */
        static final SignoutUtils INSTANCE = new SignoutUtils();
    }

    public static SignoutUtils getInstance() {
        return SignoutHolder.INSTANCE;
    }

    private SignoutUtils() {
    }

    //添加Activity
    public void addActivity(Activity activity) {
        if (null == list) {
            list = new ArrayList<Activity>();
        }
        int a = -1;
        if (list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i) == activity) {
                    a = i;
                    break;
                }
            }
        }
        if (a == -1) {
            list.add(activity);
        }
    }

    //退出
    public void exit() {
        if (null == list) {
            list = new ArrayList<Activity>();
        }
        for (int i = 0; i < list.size(); i++) {
            if (null != list.get(i)) {
                list.get(i).finish();
            }
        }
        list = null;
    }

    //销毁单个Activity
    public void destroy(Activity activity) {
        if (null == list) {
            list = new ArrayList<Activity>();
        }
        int a = -1;
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) == activity) {
                a = i;
                break;
            }
        }
        if (a != -1) {
            list.remove(a);
        }
    }

    public int size() {
        return (null != list) ? list.size() : 0;
    }



//    public String getAppkey(){
//        if (!TextUtils.isEmpty(HttpConstans.APP_KEY)) {
//            appkey = StringHttp.APP_KEY;
//
//        } else {
//            if (!TextUtils.isEmpty(SellApplication.getACache().getAsString(Constant.ACacheTag.APP_KEY))) {
//                HttpConstans.APP_KEY = SellApplication.getACache().getAsString(Constant.ACacheTag.APP_KEY);
//                appkey = HttpConstans.APP_KEY;
//
//            } else {
//                appkey = HttpConstans.APP_KEY_DUOSHU;
//            }
//        }
//
//        return appkey;
//    }
//    public String getAppsercet(){
//        if (!TextUtils.isEmpty(HttpConstans.APP_SERCET)) {
//            sercet = HttpConstans.APP_SERCET;
//
//        } else {
//            if (!TextUtils.isEmpty(SellApplication.getACache().getAsString(Constant.ACacheTag.APP_SERCET))) {
//                HttpConstans.APP_SERCET = SellApplication.getACache().getAsString(Constant.ACacheTag.APP_SERCET);
//                sercet = HttpConstans.APP_SERCET;
//
//            } else {
//                sercet = HttpConstans.APP_SERCET_DUOSHU;
//
//            }
//        }
//
//        return sercet;
//    }
}
